package indi.h.filefilter.filters;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;

import indi.h.filefilter.anaysis.Anaysis;

public class DocxImageFilter extends BasicFilter {
	private final static Logger l = Logger.getLogger(DocxImageFilter.class);

	public DocxImageFilter(Enum title) {
		super(title);
	}

	@Override
	public boolean filter(Anaysis.FileMessage af) {
		// TODO Auto-generated method stub
		super.filter(af);
		if (isFilter()) {
			l.debug("start docx image filter");
			try (InputStream i = new FileInputStream(af.getMessage()); XWPFDocument d = new XWPFDocument(i)) {
				List<XWPFPictureData> l = d.getAllPictures();
				return (!(l.size() > 0));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				l.error("FileNotFoundException:"+e.getMessage());
				return false;
			} catch (IOException e) {
				// TODO: handle exception
				l.error("IOException:"+e.getMessage());
				return false;
			}
		}
		return true;
	}
}
